home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
GNUUCP_2
/
SOURCE
/
SYSDEP.MAC
< prev
next >
Wrap
Text File
|
1989-07-31
|
8KB
|
344 lines
/*
* @(#)sysdep.mac 1.2 87/09/23 Copyright 1987 Free Software Foundation, Inc.
*
* Copying and use of this program are controlled by the terms of the
* GNU Emacs General Public License.
*/
#ifndef lint
char sysdep_version[] = "@(#)sysdep.mac gnuucp Version hoptoad-1.2";
#endif
/*
* Created 22 September 1987 by John Gilmore,
* using code from sun!seismo!psc!jsl (John Labovitz).
* His comments:
1. Logging cleanup. It makes it somewhat easier to make the
right time and date for whatever OS you're using. I made it
more modular.
2. Changes in the login routine to let it be more like real Unix
systems. I made a special routine that reads a line from the
input port, and *then* checks it, instead of only checking each
character as it comes in. Also, it handles ^D, which my Unix
systems uses to make sure there's a prompt. Doesn't handle break.
This needs some more work on the Mac side, like letting the user abort
uuslave. Right now you have to reset the machine!
Hope this is useful. I'm really interesting in running this thing, although
I'm not quite sure how I'm going to configure it (like how to read mail on
the Mac). But soon I'll be "potomac!sly!jsl". What I might do is actually
run this as a server on a PC, connected to the Unix machine via RS232, then
write a program on the Mac that can access the PC via Appletalk (aon the
MacBridge card) and get the mail. That way, any of our 30 macs can get mail
without being connected to Unix... Dreams.
*/
#include "includes.h"
#include "uucp.h"
#include "sysdep.h"
#define inPortName "\p.AIn" /* modem input port */
#define outPortName "\p.AOut" /* modem output port */
int inRefNum, outRefNum;
#define CONTROL "gnuucp.ctl"
/*
* Exported variables
*/
char sysdep_control[] = CONTROL;
/*
* Open the serial line for an incoming call.
* Argument of NULL or empty string means stdin.
* FIXME, baud rate should be settable here?
*/
int
openline(ttynam, baud)
char *ttynam;
int baud;
{
if (OpenDriver(inPortName, &inRefNum) != noErr)
return(EOF);
if (OpenDriver(outPortName, &outRefNum) != noErr)
return(EOF);
return(0);
}
/*
* Open the serial line for an outgoing call.
*/
int
openout(ttynam, baud)
char *ttynam;
int baud;
{
abort(); /* FIXME, not written */
return SUCCESS;
}
/*
* Basement level I/O routines
*
* xwrite() writes a character string to the serial port
* xgetc() returns a character from the serial port, or an EOF for timeout.
* sigint() restores the state of the serial port on exit.
* hangup() hangs up the serial port (e.g. drop DTR).
*/
void
sigint()
{
return 0; /* No-op on mac, it seems there's no way
to interrupt it! */
}
xwrite(dummy, buf, ctr)
int dummy;
char *buf;
int ctr;
{
long count;
count = ctr;
if (FSWrite(outRefNum, &count, buf) != noErr)
return(EOF);
return((int)count);
}
xgetc()
{
char data;
long count;
long i;
i = TickCount() + (BYTE_TIMEOUT * 60L);
count = 0;
while (TickCount() < i) {
SerGetBuf(inRefNum, &count);
if (count > 0) {
count = 1; /* make sure we only read one byte */
if (FSRead(inRefNum, &count, &data) != noErr)
return(EOF);
return(data & 0xFF);
}
}
return(EOF);
}
/*
* hangup(): hang up the 'fone.
*/
int
hangup()
{
abort(); /* FIXME -- write this for Mac */
sleep(2); /* To be sure DTR stays down that long */
}
/*
* Create a temporary file name for receiving a file into.
* "name" is the name we will actually eventually want to use for the file.
* We currently ignore it, but some OS's that can't move files around
* easily might want to e.g. put the temp file into the same directory
* that this file is going into.
*
* FIXME:
* This interface should be able to return a "possible" filename, and
* be re-called if the name is already in use, to get another.
* This avoids checking here whether the name is good -- saving system calls.
*/
char *
temp_filename(name)
register char *name;
{
static char tname[NAMESIZE];
if (ourpid == 0)
ourpid = getpid();
(void) sprintf(tname, "TM.u%d", ourpid);
DEBUG(7, "Using temp file %s\n", tname);
return tname;
}
/*
* Transform a filename from a uucp packet (in Unix format) into a local
* filename that will work in the local file system.
*
* This is a real hack; it puts all the files into one big directory.
* Everything. Yuk.
*/
char *
munge_filename(name)
register char *name;
{
register char *p;
static char buffer[NAMESIZE+SLOP];
int len, hostlen;
DEBUG(7, "Munge_filename input: %s\n", name);
for (p = name + strlen(name); p != name && *(p-1) != '/'; p--) ;
DEBUG(7, "Munge_filename output: %s\n", p);
return p;
}
/*
* Uucp work queue scan.
*
* gotsome = work_scan(hostname, type);
* workfile = work_next();
* void work_done();
*/
/*
* Local variables of the work queue scanner -- not visible to outsiders
*
* Workhost and worktype are always null-terminated; keeping their lengths
* is just a performance hack. Workprefix is NOT null terminated; various
* people copy things after it and use the whole string. Workprefix is
* exactly workplen long; to append something, strcpy(workprefix+workplen, ...)
*/
#define MAX_TYPE 10
static DIR *workdir = (DIR *)NULL;
static struct dirent *workfile;
static char workhost[MAX_HOST+1];
static int workhlen;
static char worktype[MAX_TYPE+1];
static int worktlen;
static char workfirst = 0;
/* FIXME, at the moment this can be local to work_scan() */
static char workprefix[MAX_TYPE+1+MAX_HOST+1+MAX_TYPE+1+MAX_HOST+6+SLOP];
/* D . hoptoad / D . hoptoad N1234\0 */
static int workplen;
void
work_done()
{
if (workdir)
closedir(workdir);
workdir = (DIR *) NULL;
workfile = (struct dirent *) NULL;
workfirst = 0;
}
int
work_scan(host, type)
char *host;
char *type;
{
char *p;
if (!host)
host = "";
/* If called twice in a row, don't thrash the disk again */
if (strcmp(workhost, host) == SAME &&
strcmp(worktype, type) == SAME && workfile)
return 1;
if (workdir) work_done(); /* Clean up prev call */
workfirst = 1; /* Initialize for work_next */
workhlen = strlen(host);
if (workhlen > sizeof (workhost) -1) abort();
strcpy(workhost, host);
if (workhlen > 7) workhlen = 7; /* Unix uucp limit */
worktlen = strlen(type);
if (worktlen > sizeof (worktype) -1) abort();
strcpy(worktype, type);
/* Figure out which subdirectory this class of files is in. */
/* FIXME: doesn't handle "all D. files" since D.myname is separate. */
sprintf(workprefix, "%s.%s", worktype, workhost);
p = munge_filename(workprefix);
strcpy(workprefix, p);
p = index(workprefix, '/');
if (p)
workplen = 1 + p - workprefix; /* Prefix ends after '/' */
else
workplen = 0; /* No / in munged; hence no dir */
workprefix[workplen] = '\0';
DEBUG(7, "Work prefix is =%s=\n", workprefix);
strcpy(workprefix+workplen, ".");
workdir = opendir(workprefix); /* Open whatever directory */
if (workdir == NULL) {
DEBUG(0, "Can't open queue directory %s\n", workprefix);
return 0; /* No work */
}
return work_look();
}
static int
work_look()
{
int len;
for (;;) {
workfile = readdir(workdir);
if (workfile == NULL) {
DEBUG(7, "work_look readdir null\n", 0);
work_done();
return 0; /* No work */
}
DEBUG(7, "work_look readdir %s\n", workfile->d_name);
/* Is it the right type? */
if (strncmp(workfile->d_name, worktype, worktlen) == SAME
&& workfile->d_name[worktlen] == '.') {
/* see if it matches the hostname */
len = strlen(workfile->d_name);
/* "C" "." "hoptoad" "Xnnnn" */
if (workhlen == 0 ||
(len == worktlen + 1 + workhlen + 5 &&
!strncmp(workhost, workfile->d_name+2, workhlen))
) {
/* Found an entry! */
/* FIXME, check grade letter! */
DEBUG(7, "work_look found it!\n", 0);
return 1; /* Found work */
}
}
}
/* NOTREACHED */
}
char *
work_next()
{
if (!workfirst) {
if (!workfile || !work_look())
return (char *)NULL;
}
workfirst = 0;
return workfile->d_name;
}